package com.yaowk.web.mall.clothing.controller;

import com.yaowk.api.common.PageReq;
import com.yaowk.api.common.PageResp;
import com.yaowk.api.mall.clothing.model.Address;
import com.yaowk.api.mall.clothing.service.IAddressService;
import com.yaowk.web.system.security.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mall/clothing/address")
@Api(tags = "会员地址控制器")
public class AddressController {

    @Autowired
    private IAddressService addressService;

    @GetMapping
    @ApiOperation("地址列表")
    public PageResp<Address> list(PageReq pageReq) {
        Address address = new Address();
        address.setMemberId(SecurityUtils.getUserId());
        PageResp<Address> pageResp = addressService.findAll(address, pageReq);
        return pageResp;
    }

    @PostMapping
    @ApiOperation("保存地址")
    public Address save(Address address) {
        address = addressService.save(address);
        return address;
    }

    @DeleteMapping
    @ApiOperation("删除地址")
    public void delete(@PathVariable Integer id) {
        addressService.deleteById(id);
    }

}
